クロス集計

library(gmodels)
data(birthwt, package = "MASS")
CrossTable(birthwt$smoke, birthwt$low, prop.r = T, prop.c = F, prop.t = F, 
    prop.chisq = F, expected = T, chisq = T, fisher = T)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## |              Expected N |
## |           N / Row Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  189 
## 
##  
##               | birthwt$low 
## birthwt$smoke |         0 |         1 | Row Total | 
## --------------|-----------|-----------|-----------|
##             0 |        86 |        29 |       115 | 
##               |    79.101 |    35.899 |           | 
##               |     0.748 |     0.252 |     0.608 | 
## --------------|-----------|-----------|-----------|
##             1 |        44 |        30 |        74 | 
##               |    50.899 |    23.101 |           | 
##               |     0.595 |     0.405 |     0.392 | 
## --------------|-----------|-----------|-----------|
##  Column Total |       130 |        59 |       189 | 
## --------------|-----------|-----------|-----------|
## 
##  
## Statistics for All Table Factors
## 
## 
## Pearson's Chi-squared test 
## ------------------------------------------------------------
## Chi^2 =  4.924     d.f. =  1     p =  0.02649 
## 
## Pearson's Chi-squared test with Yates' continuity correction 
## ------------------------------------------------------------
## Chi^2 =  4.236     d.f. =  1     p =  0.03958 
## 
##  
## Fisher's Exact Test for Count Data
## ------------------------------------------------------------
## Sample estimate odds ratio:  2.014 
## 
## Alternative hypothesis: true odds ratio is not equal to 1
## p =  0.03618 
## 95% confidence interval:  1.029 3.965 
## 
## Alternative hypothesis: true odds ratio is less than 1
## p =  0.9911 
## 95% confidence interval:  0 3.581 
## 
## Alternative hypothesis: true odds ratio is greater than 1
## p =  0.02021 
## 95% confidence interval:  1.137 Inf 
## 
## 
##